package com.zhilianbao.leyaogo.ui.adapter.me;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.model.response.me.BalanceResponse;

import java.util.List;

/**
 * Created by liu on 2016/12/5.
 */
public class BalanceListAdapter extends BaseAdapter {

    private List<BalanceResponse.RechargeGoodsItemListBean> mRechargeGoodsItemList;
    Context mContext;

    public BalanceListAdapter(Context context, List<BalanceResponse.RechargeGoodsItemListBean> rechargeGoodsItemList) {
        this.mContext = context;
        mRechargeGoodsItemList = rechargeGoodsItemList;
    }

    @Override
    public int getCount() {
        return mRechargeGoodsItemList == null ? 0 : mRechargeGoodsItemList.size();
    }

    @Override
    public Object getItem(int position) {
        if (mRechargeGoodsItemList != null) {
            return mRechargeGoodsItemList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.item_list_text, null);
            holder.name = (TextView) convertView.findViewById(R.id.balance_give);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        BalanceResponse.RechargeGoodsItemListBean rechargeGoodsItemListBean = mRechargeGoodsItemList.get(position);
        String goodsName = rechargeGoodsItemListBean.getGoodsName();
        String couponsName = rechargeGoodsItemListBean.getCouponsName();
        if (rechargeGoodsItemListBean.getItemType() == 0) {//送优惠券
            holder.name.setText(couponsName);
        } else if (rechargeGoodsItemListBean.getItemType() == 1) {//送商品
            holder.name.setText(goodsName);
        }
        return convertView;
    }

    class ViewHolder {
        TextView name;
    }
}
